{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "13714318",
   "metadata": {},
   "source": [
    "# 第二周课后作业\n",
    "\n",
    "## 1. Head First Python P4\n",
    "\n",
    "> 1. 21:14 尝试第一次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e5b5a806",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,\n",
    "        21,23,25,27,29,31,33,35,37,39,\n",
    "        41,43,45,47,49,51,53,55,57,59]\n",
    "# right_this_minute 是一个变量，是随着当前时间分钟数不断变化的一个值\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b065e01",
   "metadata": {},
   "source": [
    "> 2. 21:15 尝试第二次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0733828a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4ea11da",
   "metadata": {},
   "source": [
    "> 结论：根据自己电脑当前时间的改变，运行的结果也会随之改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d907df87",
   "metadata": {},
   "outputs": [],
   "source": [
    "from os import getcwd\n",
    "where_am_I = getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8bb9c0e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'win32'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "sys.platform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "132073e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.9.12 (main, Apr  4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]\n"
     ]
    }
   ],
   "source": [
    "print(sys.version)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dd8262c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\2022-2023\\\\python\\\\week02'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3066cee5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "environ{'ALLUSERSPROFILE': 'C:\\\\ProgramData',\n",
       "        'APPDATA': 'C:\\\\Users\\\\meng\\\\AppData\\\\Roaming',\n",
       "        'BT_PANEL': 'D:\\\\BtSoft\\\\panel',\n",
       "        'BT_PYTHON': 'C:\\\\Program Files\\\\python',\n",
       "        'BT_SETUP': 'D:\\\\BtSoft',\n",
       "        'COMMONPROGRAMFILES': 'C:\\\\Program Files\\\\Common Files',\n",
       "        'COMMONPROGRAMFILES(X86)': 'C:\\\\Program Files (x86)\\\\Common Files',\n",
       "        'COMMONPROGRAMW6432': 'C:\\\\Program Files\\\\Common Files',\n",
       "        'COMPUTERNAME': 'LAPTOP-UAULMBN8',\n",
       "        'COMSPEC': 'C:\\\\WINDOWS\\\\system32\\\\cmd.exe',\n",
       "        'DRIVERDATA': 'C:\\\\Windows\\\\System32\\\\Drivers\\\\DriverData',\n",
       "        'FPS_BROWSER_APP_PROFILE_STRING': 'Internet Explorer',\n",
       "        'FPS_BROWSER_USER_PROFILE_STRING': 'Default',\n",
       "        'HOMEDRIVE': 'C:',\n",
       "        'HOMEPATH': '\\\\Users\\\\meng',\n",
       "        'INTEL_DEV_REDIST': 'C:\\\\Program Files (x86)\\\\Common Files\\\\Intel\\\\Shared Libraries\\\\',\n",
       "        'LOCALAPPDATA': 'C:\\\\Users\\\\meng\\\\AppData\\\\Local',\n",
       "        'LOGONSERVER': '\\\\\\\\LAPTOP-UAULMBN8',\n",
       "        'MIC_LD_LIBRARY_PATH': 'C:\\\\Program Files (x86)\\\\Common Files\\\\Intel\\\\Shared Libraries\\\\compiler\\\\lib\\\\mic',\n",
       "        'NUMBER_OF_PROCESSORS': '16',\n",
       "        'ONEDRIVE': 'C:\\\\Users\\\\萌\\\\OneDrive',\n",
       "        'ONEDRIVECONSUMER': 'C:\\\\Users\\\\萌\\\\OneDrive',\n",
       "        'OS': 'Windows_NT',\n",
       "        'PATH': 'C:\\\\Program Files (x86)\\\\Common Files\\\\Intel\\\\Shared Libraries\\\\redist\\\\intel64\\\\compiler;C:\\\\WINDOWS\\\\system32;C:\\\\WINDOWS;C:\\\\WINDOWS\\\\System32\\\\Wbem;C:\\\\WINDOWS\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\;C:\\\\WINDOWS\\\\System32\\\\OpenSSH\\\\;C:\\\\Program Files\\\\python;C:\\\\Program Files\\\\python\\\\Scripts;D:\\\\BtSoft\\\\panel\\\\script;C:\\\\Program Files\\\\Git\\\\cmd;D:\\\\anacondaxuexi;D:\\\\anacondaxuexi\\\\Scripts;D:\\\\anacondaxuexi\\\\Library\\\\mingw-w64\\\\bin;D:\\\\anacondaxuexi\\\\Library\\\\usr\\\\bin;D:\\\\anacondaxuexi\\\\Library\\\\bin;C:\\\\Users\\\\萌\\\\AppData\\\\Local\\\\Programs\\\\Python\\\\Python310\\\\Scripts\\\\;C:\\\\Users\\\\萌\\\\AppData\\\\Local\\\\Programs\\\\Python\\\\Python310\\\\;C:\\\\Users\\\\meng\\\\AppData\\\\Local\\\\Microsoft\\\\WindowsApps;C:\\\\Users\\\\萌\\\\AppData\\\\Local\\\\GitHubDesktop\\\\bin;',\n",
       "        'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',\n",
       "        'PROCESSOR_ARCHITECTURE': 'AMD64',\n",
       "        'PROCESSOR_IDENTIFIER': 'AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD',\n",
       "        'PROCESSOR_LEVEL': '25',\n",
       "        'PROCESSOR_REVISION': '5000',\n",
       "        'PROGRAMDATA': 'C:\\\\ProgramData',\n",
       "        'PROGRAMFILES': 'C:\\\\Program Files',\n",
       "        'PROGRAMFILES(X86)': 'C:\\\\Program Files (x86)',\n",
       "        'PROGRAMW6432': 'C:\\\\Program Files',\n",
       "        'PROMPT': '$P$G',\n",
       "        'PSMODULEPATH': 'C:\\\\Program Files\\\\WindowsPowerShell\\\\Modules;C:\\\\WINDOWS\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\Modules',\n",
       "        'PUBLIC': 'C:\\\\Users\\\\Public',\n",
       "        'SESSIONNAME': 'Console',\n",
       "        'SYSTEMDRIVE': 'C:',\n",
       "        'SYSTEMROOT': 'C:\\\\WINDOWS',\n",
       "        'TEMP': 'C:\\\\Users\\\\meng\\\\AppData\\\\Local\\\\Temp',\n",
       "        'TMP': 'C:\\\\Users\\\\meng\\\\AppData\\\\Local\\\\Temp',\n",
       "        'UNRAR_LIB_PATH': 'C:\\\\Program Files\\\\python\\\\Lib\\\\site-packages\\\\unrar\\\\UnRAR.dll',\n",
       "        'USERDOMAIN': 'LAPTOP-UAULMBN8',\n",
       "        'USERDOMAIN_ROAMINGPROFILE': 'LAPTOP-UAULMBN8',\n",
       "        'USERNAME': 'meng',\n",
       "        'USERPROFILE': 'C:\\\\Users\\\\meng',\n",
       "        'WINDIR': 'C:\\\\WINDOWS',\n",
       "        'PYDEVD_USE_FRAME_EVAL': 'NO',\n",
       "        'JPY_INTERRUPT_EVENT': '2492',\n",
       "        'IPY_INTERRUPT_EVENT': '2492',\n",
       "        'JPY_PARENT_PID': '2384',\n",
       "        'TERM': 'xterm-color',\n",
       "        'CLICOLOR': '1',\n",
       "        'PAGER': 'cat',\n",
       "        'GIT_PAGER': 'cat',\n",
       "        'MPLBACKEND': 'module://matplotlib_inline.backend_inline'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.environ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "42bdc208",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\\\Users\\\\meng'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.getenv('HOMEPATH')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "cf0a1a19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.date(2022, 9, 4)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import datetime\n",
    "datetime.date.today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "26be666a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2022"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today().year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d39af737",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today().month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8cf9091c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today().day"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1e4b928",
   "metadata": {},
   "source": [
    "## 课堂上的补充"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9e44de0f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15\n",
      "现在是秒/时间为奇数\n",
      "等待时间为: 4\n",
      "19\n",
      "现在是秒/时间为奇数\n",
      "等待时间为: 3\n",
      "22\n",
      "现在是秒/时间为偶数\n",
      "等待时间为: 2\n",
      "24\n",
      "现在是秒/时间为偶数\n",
      "等待时间为: 5\n",
      "29\n",
      "现在是秒/时间为奇数\n",
      "等待时间为: 4\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import random\n",
    "import time\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,\n",
    "        21,23,25,27,29,31,33,35,37,39,\n",
    "        41,43,45,47,49,51,53,55,57,59]\n",
    "# right_this_second 是一个变量，是随着当前时间分钟数不断变化的一个值\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "        print(right_this_second)\n",
    "        print(\"现在是秒/时间为奇数\")\n",
    "    else:\n",
    "        print(right_this_second)\n",
    "        print(\"现在是秒/时间为偶数\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    print(\"等待时间为:\", wait_time)\n",
    "    time.sleep(wait_time)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1641d4e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
